package com.jd.controller;

import com.alibaba.csp.sentinel.annotation.SentinelResource;
import com.alibaba.csp.sentinel.slots.block.BlockException;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author wangshuping
 * @version 1.0
 * @date 2021/12/22 11:20
 */
@RestController
@RequestMapping("/hot")
public class HotKeyController {

    @GetMapping("testHotKey")
    @SentinelResource(value = "/testHotKey", blockHandler = "testHotKeyFallback")
    public String testHotKey(
            @RequestParam(required = false) String key01,
            @RequestParam(required = false) String key02,
            @RequestParam(required = false) String key03) {
        if("6".equals(key02)){
            throw new RuntimeException("运行时异常");
        }
        return "testHotKey";
    }

    public String testHotKeyFallback(String key01, String key02, String key03, BlockException exception) {
        return "触发热点限流," + exception.getRuleLimitApp();
    }

}
